-
Notifications
You must be signed in to change notification settings - Fork 152
Aliases for 2D and 3D Float64 vectors. #655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
In my opinion, this is not a good idea. What makes And then there's #24 (comment), #24 (comment), and #24 (comment). |
Hi, thanks for the PR! However I don't think we should privilege If we did want short forms, some naming inspiration could come from
Perhaps you can describe your use case, especially if it's not covered by the above? |
Twan, I think you're right about the Float64 vs Float32. Currently we do declare them in our own packages. It's just that we declare it again and again. At some point, someone will indeed decide to make Vector3D in another package a Float32 vector and then suddenly Vector3D means different things in different packages... So it seemed nice to declare it in a common place. Better to do just that but in another shared module. |
This is an interesting idea that I haven't seen discussed before. But I think a flaw is that the natural follow-up PR would be to add
Also, you'd still be repeating @c42f brings up good points. What's the main quality-of-life improvement you're looking for? By the way, in Eigen, |
Yes, you'd be repeating the using, but you'd won't override Vector3D (with the same thing, but new line of code) when using two packages that both define Vector3D. And there would be no code duplication in case something would ever change about Vector3D. |
W.r.t the quality of life, Vector3D is simply more readable than SVector{3, Float64}. A list of points would be Vector{Vector3D}, which is clear, but Vector{SVector{3,Float64}} already becomes distracting when you want to quickly see what code does... |
I certainly agree with that. But can you describe the specific circumstances in which you typically need to write By the way, I definitely don't think we should have |
Just exploring options! I also feel there's something fishy about that. |
For sure, I'm happy to have the discussion. To be clear, I highly value usability and I'd like to merge a PR which makes things easier for you while respecting the generic nature of the library. It's just that resolving those two things together is difficult because our types are highly parametric in both shape and eltype so it's hard to be consistent and also avoid massive namespace pollution. An option is to simply define a submodule julia> module Aliases
using StaticArrays
for (T,tn) in [(Float32, "F32"), (Float64, "F64")]
for L in [2,3,4]
name = Symbol("Vec$L$tn")
@eval const $name = SVector{$L, $T}
mname = Symbol("Mat$L$L$tn")
@eval const $mname = SMatrix{$L, $L, $T}
@eval export $name, $mname
end
end
end
WARNING: replacing module Aliases.
Main.Aliases
julia> names(Aliases)
13-element Array{Symbol,1}:
:Aliases
:Mat22F32
:Mat22F64
:Mat33F32
:Mat33F64
:Mat44F32
:Mat44F64
:Vec2F32
:Vec2F64
:Vec3F32
:Vec3F64
:Vec4F32
:Vec4F64 Eh, I'm not sure I find this terribly compelling though. Another option would be to define some type aliases for eltypes of Float32 and Float64, for example const SVectorF32{N} = SVector{N,Float32}
const SMatrixF64{N,M} = SMatrix{N,M,Float64} This might be more useful because having a name for commonly used eltypes is more managable than having a big pile of names for each dimensionality. (Unfortunately |
I think a reasonable compromise solution here is to use #633 and to add some type aliases: SA_F64 = SA{Float64}
SA_F32 = SA{Float32}
v = SA_F64[1,2,3] # A Float64 vector
v = SA_F32[1 2; 3 4] # A 2x2 Float32 SMatrix I don't love the underscore there, but This solves the issue of constructing these types with a precise |
I've implemented the I'm going to close this PR, as I'm not sure what further action we can take here. But please do continue the discussion, especially if you have some motivating use cases which can be clearly described. |
Thanks again guys!! A good step I think. |
To simplify working with 3D data, an easy and familiar alias for 2D and 3D vectors.